package ft.app.gtig.entity;

import com.haulmont.cuba.core.entity.StandardEntity;

import javax.persistence.*;
import java.util.List;

@Table(name = "GTIG_ABOUT_US")
@Entity(name = "gtig$AboutUs")
public class AboutUs extends StandardEntity {
    private static final long serialVersionUID = 7890605213913836636L;

    @Column(name = "NAME", nullable = false, length = 50)
    protected String name;

    @Column(name = "TYPE_", nullable = false)
    protected Integer type;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ARTICLE_ID")
    protected Article article;

    @JoinTable(name = "GTIG_ABOUT_US_PERSON_LINK",
        joinColumns = @JoinColumn(name = "ABOUT_US_ID"),
        inverseJoinColumns = @JoinColumn(name = "PERSON_ID"))
    @OrderBy("updateTs DESC")
    @ManyToMany
    protected List<Person> persons;

    @Column(name = "SORT", nullable = false)
    protected Integer sort;

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public Integer getSort() {
        return sort;
    }


    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setType(AboutUsTypeEnum type) {
        this.type = type == null ? null : type.getId();
    }

    public AboutUsTypeEnum getType() {
        return type == null ? null : AboutUsTypeEnum.fromId(type);
    }

    public void setArticle(Article article) {
        this.article = article;
    }

    public Article getArticle() {
        return article;
    }

    public void setPersons(List<Person> persons) {
        this.persons = persons;
    }

    public List<Person> getPersons() {
        return persons;
    }


}